package result;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author 化尘成影
 * @Description 响应结果类
 * @date 2022/6/9 20:00
 */
public class CodeMsg implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    private Integer code;
    private String msg;

    //通用
    public final static CodeMsg SUCCESS = new CodeMsg(200,"成功");
    public final static CodeMsg HAVE_EXISTENCE_ERROR = new CodeMsg(401,"用户已经存在");
    public final static CodeMsg NOT_EXISTENCE_ERROR = new CodeMsg(402,"用户不存在");
    public final static CodeMsg PASSWORD_ERROR = new CodeMsg(403,"密码错误");
    public final static CodeMsg DEFAULT = new CodeMsg(404,"失败");
    public final static CodeMsg HAVE_LOGIN = new CodeMsg(405,"该玩家已经在登录状态");
    public final static CodeMsg ROOM_ID_NOT_EXISTENCE = new CodeMsg(406,"房间号不存在");
    public final static CodeMsg ROOM_ID_HAVE_EXISTENCE = new CodeMsg(407,"房间号已经存在");
    public final static CodeMsg IP_EXISTENT = new CodeMsg(500,"一个设备只能登录一个账号");
    public final static CodeMsg SERVICE_ERROR = new CodeMsg(503,"服务器错误");

    //token
    public final static CodeMsg TOKEN_INVALID = new CodeMsg(601,"token无效");
    public final static CodeMsg TOKEN_OUT_TIME = new CodeMsg(602,"token过期");

    public static CodeMsg success(String data){
        return new CodeMsg(CodeMsg.SUCCESS.getCode(), CodeMsg.SUCCESS.getMsg(),data);
    }

    public CodeMsg() {
    }

    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg(int code,String msg,String data){
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
